﻿Shader "Unlit/MotionBlur"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _BlurAmount("BlurAmount（运动模糊强度）",Float) = 1.0
    }
    SubShader
    {
        CGINCLUDE
            #include "UnityCG.cginc"

            sampler2D _MainTex;
            fixed _BlurAmount;

            struct a2v
            {
                float4 vertex : POSITION;
                float2 texcoord : TEXCOORD0;
            };
            struct v2f
            {
                float4 pos : SV_POSITION;
                float2 uv : TEXCOORD0;
            };
            v2f vert (a2v v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                o.uv = v.texcoord;
                return o;
            }
            //更新RGB
            fixed4 fragRGB(v2f i) : SV_TARGET
            {
                return fixed4(tex2D(_MainTex,i.uv).rgb,_BlurAmount);
            }
            //更新A
            half4 fragA(v2f i) : SV_TARGET
            {
                return tex2D(_MainTex,i.uv);
            }
        ENDCG

        ZTest Always Cull Off ZWrite Off
        Pass
        {
            Blend SrcAlpha OneMinusSrcAlpha
            ColorMask RGB

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment fragRGB
            ENDCG
        }
        pass
        {
            Blend One Zero
            ColorMask A
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment fragA
            ENDCG
        }
    }
    Fallback Off
}
